<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title th:text="${detail.a_title}"></title>
    <link rel="stylesheet" href="/css/commone.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/commone.css">
    <link rel="stylesheet" href="/css/commthree.css">
    <link rel="stylesheet" href="/css/commtwo.css">
    <link rel="stylesheet" href="/css/pinglun.css">
    <link rel="stylesheet" href="/css/layer.css" id="layuicss-layer">
    <link rel="shortcut icon" href="http://www.hasbei.com/static/images/icon.png" type="image/x-icon">


    <link rel="stylesheet" media="screen and (min-width:481px)" href="/css/condetail.css">
    <link rel="stylesheet" media="screen and (max-width:480px)" href="/css/condetail(1).css">

    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="/layui-v2.5.6/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<div class="content">

    <div th:include="/user_page/usercenter_head :: usercenterhead"></div>
    <!-- 所有栏目 -->
    <!--<div>
        <ul class="layui-nav layui-bg-blue">
            <li class="layui-nav-item" th:each="title,info : ${titlelist}">
                <a th:href="@{'/zx/sort/' + ${title.tid}}">
                    <span th:text="${title.tname}"></span>
                </a>
            </li>
        </ul>
    </div> -->
    <div class="content-main">
        <div class="main-tab">
            <div class="max-width">
                <ul class="main-tab-ul">
                    <!-- <li class=""><a href="/" target="_self">首页</a></li> -->
                    <li class=""><a href="/zx" target="_self">今日推荐</a></li>
                    <li th:each="title,info : ${titlelist}" th:if="${info.index < 9}">
                        <a th:href="@{'/zx/sort/' + ${title.tid}}">
                            <span th:text="${title.tname}"></span>
                        </a>
                    </li>

                    <li class="tab-more-list">
                        <a href="javascript:;" target="_self">
                            <span>更多</span>
                            <img class="arrow-bottom" src="http://www.hasbei.com/static/images/arrow-bttom.png"
                                 alt="有贝口腔网">
                        </a>
                        <div>
                            <ul>
                                <li th:each="title,info : ${titlelist}" th:if="${info.index > 8}">
                                    <a th:href="@{'/zx/sort/' + ${title.tid}}">
                                        <span th:text="${title.tname}"></span>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <div>
            <!-- 所在位置导航 -->
            <div class="bread-crumb">
                <div>
                    <a href="">首页</a>
                    <span>/</span>
                    <a th:href="@{'/zx/sort/' + ${detail.a_tid}}">
                        <span th:text="${detail.a_create_date}"></span>
                    </a>
                    <span>/</span>
                    <a th:href="@{'/zx/detail/' + ${detail.id}}">
                        <span th:text="${detail.a_title}"></span>
                    </a>
                </div>
            </div>
            <!-- 文章 和 其他看点 -->
            <div class="zixun-info">
                <div>
                    <div class="artical-info">
                        <div class="artical-title">
                            <div class="list-item-title title-content">
                                <a th:href="@{'/zx/detail/' + ${detail.id}}">
                                    <span th:text="${detail.a_title}"></span>
                                </a>
                            </div>
                            <div class="list-item-info">
                                <a th:href="@{'/zx/sort/' + ${detail.a_tid}}">
                                    <span class="tui-jian" th:text="${detail.a_create_date}">
                                    </span>
                                </a>
                                <div class="yue-du">
                                    <a th:href="@{'/zx/detail/' + ${detail.id}}">
                                        <img src="http://www.hasbei.com/static/images//yuedu.png">
                                        <span th:text="${detail.a_read_sum}"></span>
                                        <span>阅读</span>
                                    </a>
                                </div>
                                <span class="dotted">·</span>
                                <span class="time-before" th:text="${detail.a_ok_date}"></span>
                            </div>
                        </div>
                        <div><p></p>
                            <p style="text-align:center">
                        </div>
                        <div class="artical-content">
                            <div class="artical-text">
                                <p th:text="${detail.a_abstract}"></p>
                                <p>
                                    <img th:if="${detail.a_img_url}  ne ''" th:src="${detail.a_img_url}" title="" alt=""
                                         width="326" height="234">
                                </p>
                                <p th:text="${detail.a_content}"></p>
                            </div>
                        </div>
                        <div class="up-load">
                            <div class="bshare-custom icon-medium">
                                <div class="bsPromo bsPromo2"></div>
                                <a title="分享到QQ空间" class="bshare-qzone"></a><a title="分享到QQ好友" class="bshare-qqim"
                                                                               href="javascript:void(0);"></a><a
                                    title="分享到微信" class="bshare-weixin" href="javascript:void(0);"></a><a
                                    title="分享到新浪微博" class="bshare-sinaminiblog"></a><a title="分享到腾讯微博"
                                                                                       class="bshare-qqmb"></a><a
                                    title="分享到i贴吧" class="bshare-itieba" href="javascript:void(0);"></a><a title="更多平台"
                                                                                                           class="bshare-more bshare-more-icon more-style-addthis"></a><span
                                    class="BSHARE_COUNT bshare-share-count" style="float: none;">9</span></div>
                            <script type="text/javascript" charset="utf-8"
                                    src="http://static.bshare.cn/b/buttonLite.js#style=-1&amp;uuid=&amp;pophcol=2&amp;lang=zh"></script>
                            <script type="text/javascript" charset="utf-8"
                                    src="http://static.bshare.cn/b/bshareC0.js"></script>
                        </div>

                        <input type="hidden" id="no" value="202007151283316478564765696">
                        <input type="hidden" id="collectType" value="10">

                        <!--                        <div class="artical-edit">
                                                    <div class="artical-edit-left">
                                                        <a href="javascript:;"><em id="commentCount" th:text="${detail.a_comment_sum}"></em>&nbsp;条评论</a>
                                                        <a href="javascript:;" id="collectCount"><span th:text="${detail.a_collet_sum}"></span>人收藏</a>
                                                    </div>
                                                    <div class="artical-edit-right">
                                                        <a href="javaScript:;" onclick="collect()"><img
                                                                src="http://www.hasbei.com/static/images/shoucang1.png"
                                                                alt="有贝口腔网"><span>收藏</span></a>
                                                    </div>
                                                    <div class="artical-edit-right">
                                                        <a href="javaScript:;" onclick="collect()">
                                                            <img src="http://www.hasbei.com/static/images/shoucang1.png"
                                                                 alt="有贝口腔网"><span>收藏</span></a>
                                                        <a href="javaScript:;" onclick="unCollect()" style="display: none">
                                                            <img src="http://www.hasbei.com/static/images/shoucang-active.png"
                                                                 alt="有贝口腔网"><span>取消收藏</span></a>
                                                    </div>
                                                </div>-->

                        <div class="pinglun">

                            <div class="publish-discuss">
                                <div class="user-logo">
                                    <a href="/user/1285053398860828672">
                                        <img th:if="${loginUser} eq null" src="/icon/user_Default.png">
                                        <img th:if="${loginUser}" th:src="@{${loginUser.getU_img_url()}}">
                                    </a>

                                </div>
                                <div class="discuss-input" style="height: 40px;">
                                    <textarea th:onfocus="|javascript:acquire(this)|" placeholder="写下您的评论..."
                                              class="textarea" th:id="'commentContent'+${detail.id}"></textarea>
                                    <div class="answer-div" style="position: absolute;">
                                        <span class="answer-btn"
                                              th:onclick="|javascript:btdAddComment(this,${detail.id},0)|">评论</span>
                                    </div>
                                </div>
                            </div>

                            <div class="discuss-box" id="commentList">
                                <!--显示评论-->
                            </div>

                            <div class="show-more" th:onclick="|javascript:moreCommentlist(this)|">查看更多评论</div>

                        </div>

                    </div>
                </div>
                <div class="aside-left margin-t0">
                    <div class="wonderful-top">
                        <div class="wonderful-top-title">其他看点</div>
                        <a th:each="ot,info : ${other}" th:href="@{'/zx/detail/' + ${ot.id}}">
                            <div class="wonderful-item-style">
                                <div class="wonderful-item-icon"><span></span></div>
                                <div th:text="${ot.a_title}"></div>
                            </div>
                        </a>
                    </div>
                </div>
            </div>
            <!-- 相关推荐 -->
            <div class="zixun-info">
                <div class="artical-info">
                    <div class="hot-title"><span>相关推荐</span></div>
                    <div id="myContentList">
                        <ul class="flow-default" id="LAY_demo2"></ul>
                    </div>
                </div>
            </div>

            <div class="content-foot">
                <div th:include="/user_page/usercenter_footer :: footer"></div>
            </div>
        </div>
    </div>
</div>
<script src="/layui-v2.5.6/layui/layui.js" charset="utf-8"></script>
<script>
    var current = 1;

    layui.use('flow', function () {
        var flow = layui.flow;
        var sort = [[${detail.a_tid}]];
        var maxpage = 0;
        $.get("/page/" + sort, function (data, status) {
            maxpage = data;
        });
        flow.load({
            elem: '#LAY_demo2' //流加载容器
            , scrollElem: '#LAY_demo2' //滚动条所在元素，一般不用填，此处只是演示需要。
            , isAuto: false
            , isLazyimg: true
            , done: function (page, next) { //加载下一页
                //模拟插入
                setTimeout(function () {
                    $.get("/recommend/" + current + "/" + sort, function (data) {
                        var lis = [];
                        lis.push(data);
                        next(lis.join(''), page < maxpage);
                        current++;
                    });
                }, 500);
            }
        });
    });
</script>
<script>
    /*function collect() {
        var CollectVO = {};
        if ([[${userId}]] != 0) {
            CollectVO.c_textl_id = [[${detail.id}]];
            CollectVO.c_user_id = [[${userId}]];
            $.post("/zx/insert/collect", CollectVO, function (data) {
                console.log(data);
            });
        } else {
            window.location.href = "/login";
        }
    }

    function unCollect() {
        var CollectVO = {};
        if ([[${userId}]] != 0) {
            CollectVO.c_textl_id = [[${detail.id}]];
            CollectVO.c_user_id = [[${userId}]];
            $.post("/zx/delete/collect", CollectVO, function (data) {
                console.log(data);
            });
        } else {
            window.location.href = "/login";
        }
    }*/
</script>
<script src="/layer-v3.1.1/layer/mobile/layer.js" type="text/javascript"></script>
<script th:inline="javascript">
        var $ = layui.jquery
            , upload = layui.upload;
        var commentPages = {
            startPage: 1,
            pageSize: 5,
            state: 1,
            type: 1,
            parentId: [[${detail.id}]]
        }

        $(function () {
            //查询评论
            inquireComment(commentPages);
        })

        //点击查询更多评论事件
        function moreCommentlist(thisDom) {
            commentPages.startPage++;

            //查询评论
            inquireComment(commentPages, thisDom);
        }

        //查询评论
        function inquireComment(commentPages, thisDom) {
            $.ajax({
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "/comment/inquirePagesDataHtml",
                //数据，json字符串
                data: JSON.stringify(commentPages),
                success: function (data) {
                    if (data != null && data != '') {
                        //console.log(data);
                        if (commentPages.startPage > 1) {//追加
                            $("#commentList").append(data);
                        } else {//替换
                            $("#commentList").html(data);
                        }
                    } else {
                        if (commentPages.startPage > 1) {
                            alert("无评论");
                            $(thisDom).css("display", "none");
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("链接错误,请联系管理员");
                }
            });
        }

        //输入框获得焦点
        function acquire(thisDom) {
            //缩小所有输入框
            $(".discuss-input").css("height", "40px");
            $(".discuss-input").find(".answer-div").css("position", "absolute");
            $("textarea").removeClass("textarea-train");
            //放大当前获得焦点的输入框
            $(thisDom).parent().css("height", "auto");
            $(thisDom).next().css("position", "static");
            $(thisDom).addClass("textarea-train");
        }

        //添加评论
        function btdAddComment(thisDom, parentId, textId) {

            //登录判断
            if (![[${detail.id}]]) {
                window.location.href = '/login';
                return false;
            }

            var comment = {};
            var userId = [[${userId}]];

            if (textId) {//回复
                var content = "";

                if (parentId == textId) {//评论回复
                    content = $("#content" + parentId).val();//内容
                    comment = {
                        ccontent: content,
                        cuserId: userId,
                        cparentId: parentId,
                        ctextId: textId,
                        ctype: 3
                    }

                } else {//回复回复
                    content = $("#contentTo" + parentId).val();//内容
                    comment = {
                        ccontent: content,
                        cuserId: userId,
                        cparentId: parentId,
                        ctextId: textId,
                        ctype: 3
                    }
                }

                if (content == "" || content == null) {
                    alert("亲,回复内容不能为空哦！");
                    return false;
                }

            } else {//评论
                var content = $("#commentContent" + parentId).val();
                comment = {
                    ccontent: content,
                    cuserId: userId,
                    cparentId: parentId,
                    ctype: 1
                }
                if (content == "" || content == null) {
                    alert("亲,评论内容不能为空哦！");
                    return false;
                }
            }
            console.log(comment);
            $.ajax({
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "/comment/add",
                //数据，json字符串
                data: JSON.stringify(comment),
                success: function (data) {
                    if (data.boo) {//成功
                        var id = data.data;
                        if (textId) {//回复
                            if (parentId == textId) {//评论回复
                                //清空输入框
                                $("#content" + parentId).val('');
                            } else {//回复回复
                                //清空输入框
                                $("#contentTo" + parentId).val('');
                            }
                            //将添加的评论回复渲染到页面
                            inquireRevertById(id, parentId, textId);
                            alert("亲,回复成功了^ v ^！");
                        } else {//评论
                            //清空输入框
                            $("#commentContent" + parentId).val('');
                            //将添加的评论渲染到页面
                            inquireCommentById(id, parentId, textId);
                            alert("亲,评论成功了^ v ^！");
                        }
                    } else {//失败
                        if (textId) {
                            alert("亲,回复失败了- _ -！");
                        } else {
                            alert("亲,评论失败了- _ -！");
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("链接错误,请联系管理员");
                }
            });
        }

        //根据id查询评论
        function inquireCommentById(id, articleId, textId) {
            $.ajax({
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "/comment/inquireCommentByIdHtml/" + id,
                success: function (data) {
                    if (data != null) {
                        //显示
                        $("#commentList" + articleId).prepend(data);
                    } else {

                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("链接错误,请联系管理员");
                }
            });
        }

        //根据id查询评论的回复
        function inquireRevertById(id, parentId, textId) {
            $.ajax({
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "/comment/inquireRevertByIdHtml/" + id,
                success: function (data) {
                    if (data != null) {
                        //console.log(data);
                        //显示
                        if (parentId == textId) {//评论回复
                            $("#revertList" + parentId).css("display", "");
                            //渲染到页面
                            $("#revertList" + parentId).prepend(data);
                        } else {//回复回复
                            //渲染到页面
                            $("#revertList" + textId).prepend(data);
                        }

                    } else {

                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("链接错误,请联系管理员");
                }
            });
        }


        var revertPages = {
            startPage: 1,
            pageSize: 5,
            state: 1,
            type: 3,
            textId: 0
        }

        //查询回复（textId就是评论id）
        function inquireRever(thisDom, textId) {
            var $revertList = $("#revertList" + textId);
            var val = $revertList.css("display");
            if (val == "none") {
                //关闭所有打开的回复显示
                $(".more-answer").css("display", "none");
                $(".answer-num").find(".arrow-img").removeClass("arrow-img-train");

                $revertList.css("display", "");
                $("#answer-num" + textId).find(".arrow-img").addClass("arrow-img-train");

                revertPages = {//初始化
                    startPage: 1,
                    pageSize: 5,
                    state: 1,
                    type: 3,
                    textId: textId
                }
                inquireRevert(thisDom, textId);//查询回复

                //显示更多按钮
                $("#revertList" + textId).next().css("display", "");
            } else {
                $revertList.css("display", "none");
                $("#answer-num" + textId).find(".arrow-img").removeClass("arrow-img-train");

                //关闭更多按钮
                $("#revertList" + textId).next().css("display", "none");
            }
            console.log(val)
        }

        //点击查询更多回复
        function moreCommentReplylist(thisDom, textId) {
            revertPages.startPage++;
            revertPages.textId = textId;
            inquireRevert(thisDom, textId);//查询回复
        }

        //点赞
        function commrntPraise(thisDom, textId) {
            alert("点你妈")
        }

        //查询回复
        function inquireRevert(thisDom, textId) {
            $.ajax({
                type: "POST",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "/comment/inquirePagesRevertDataHtml",
                //数据，json字符串
                data: JSON.stringify(revertPages),
                success: function (data) {
                    if (data != null && data != '') {
                        if (revertPages.startPage > 1) {//追加
                            $("#revertList" + textId).append(data);
                        } else {//替换
                            $("#revertList" + textId).html(data);
                        }
                    } else {
                        alert("亲,已经到底了哦！");
                        $(thisDom).next().css("display", "none");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("链接错误,请联系管理员");
                }
            });
        }

        //点击回复事件
        function addlike(thisDom, commentId) {
            //缩小所有输入框
            $(".discuss-input").css("height", "40px");
            $(".discuss-input").find(".answer-div").css("position", "absolute");
            $("textarea").removeClass("textarea-train");

            $('.posi-input').css("display", "none");
            $('.erji-input').css("display", "none");
            $('#posi-input' + commentId).css("display", "");
        }

        //点击回复的回复事件
        function addlike_s(thisDom, commentId) {
            //缩小所有输入框
            $(".discuss-input").css("height", "40px");
            $(".discuss-input").find(".answer-div").css("position", "absolute");
            $("textarea").removeClass("textarea-train");

            $('.posi-input').css("display", "none");
            $('.erji-input').css("display", "none");
            $('#erji-input' + commentId).css("display", "");
        }
</script>
</body>
</html>